import pymysql
def saveToDb(*data):
    data=(data[0],data[1][0],data[1][1],data[1][2],data[1][3])
    print(data)
    db = pymysql.connect(host='localhost', user='root', password='root', database='mytestdb', port=3306, charset='utf8')

    cursor=db.cursor()

    sql='insert into cpu(insert_time,cpu1,cpu2,cpu3,cpu4) values(%s,%s,%s,%s,%s)'
    try:
        cursor.execute(sql,data)
        db.commit()
    except Exception as e:
        print(e)
        db.rollback()
    db.close()


def query_db(query,args=(),one=False ):
    # db = pymysql.connect('localhost', 'root', 'root', 'mytestdb', charset='utf8')
    db = pymysql.connect(host='localhost', user='root', password='root', database='mytestdb', port=3306, charset='utf8')
    cursor=db.cursor()

    try:
        print('*** args=>',args)
        cursor.execute(query,args)
        results=cursor.fetchall()
    except Exception as e:
        print("error ",e)
    db.close()
    return results